package com.gsta.cdn.cdr.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.gsta.cdn.cdr.entity.ChannelConcurrent;
import com.gsta.cdn.cdr.entity.ResultEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Mapper
@Component(value = "CIDCompleteMapper")

public interface CIDCompleteMapper extends BaseMapper<ResultEntity> {

    @Select("<script>" +
            " SELECT DISTINCT Date,CompletePercent FROM ConcurrentHotAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDCompleteAll(@Param("Date") String Date,@Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT DISTINCT Date,CompletePercent FROM ConcurrentHotAll  " +
            " WHERE Date LIKE CONCAT(#{Date},'%'))t  "+
            "</script>")
    int CIDCompleteAllCount (@Param("Date") String Date);


    @Select("<script>" +
            " SELECT DISTINCT Area FROM ConcurrentHotArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  "+
            "ORDER BY Area " +
            "</script>")
    List<Map<String, Object>> CIDCompleteArea(@Param("Date") String Date);

    @Select("<script>" +
            " SELECT DISTINCT Date, Area,CompletePercent FROM ConcurrentHotArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%') AND  Area =#{Area} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDCompleteByArea(@Param("Date") String Date,@Param("Area") String Area,
                                                @Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT DISTINCT Date, Area,CompletePercent FROM ConcurrentHotArea  " +
            " WHERE Date LIKE CONCAT(#{Date},'%') AND  Area =#{Area} )t "+
            "</script>")
    int CIDCompleteByAreaCount(@Param("Date") String Date,@Param("Area") String Area);

    @Select("<script>" +
            " SELECT DISTINCT PopName FROM ConcurrentHotAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%') AND  Area =#{Area} "+
            "</script>")
    List<Map<String, Object>> CIDCompleteAreaPopName(@Param("Date") String Date,@Param("Area") String Area);


    @Select("<script>" +
            " SELECT DISTINCT Date, Area,PopName,CompletePercent FROM ConcurrentHotAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%') AND  Area =#{Area} AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDCompleteByAreaPopName(@Param("Date") String Date,@Param("Area") String Area,@Param("PopName") String PopName,
                                                @Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT DISTINCT Date, Area,PopName,CompletePercent FROM ConcurrentHotAreaPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%') AND  Area =#{Area} AND PopName=#{PopName})t "+
            "</script>")
    int CIDCompleteByAreaPopNameCount(@Param("Date") String Date,@Param("Area") String Area,@Param("PopName") String PopName);

    @Select("<script>" +
            " SELECT DISTINCT Date,PopName,CompletePercent FROM ConcurrentHotPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND PopName=#{PopName} "+
            "ORDER BY Date " +
            "LIMIT #{page},#{pageSize} "+
            "</script>")
    List<Map<String, Object>> CIDCompleteByPopName(@Param("Date") String Date,@Param("PopName") String PopName,
                                                       @Param("page") int page,@Param("pageSize") int pageSize);

    @Select("<script>" +
            "SELECT COUNT(*) AS count FROM ( " +
            " SELECT DISTINCT Date,PopName,CompletePercent FROM ConcurrentHotPopName  " +
            " WHERE Date LIKE CONCAT(#{Date},'%')  AND PopName=#{PopName})t "+
            "</script>")
    int CIDCompleteByPopNameCount(@Param("Date") String Date,@Param("PopName") String PopName);
}
